﻿#This file defines all bottom button events.
#Created: 31/11 - 2011
#By: Adam Lewenhaupt

def TexReloadButton_OnMouseLeftReleased(s, e):
    s.Parent.GetChild('TexturesListBox').SetItems(List[object](Textures.values()), System.Func[object, agi.Item](lambda d: texToItem(d)))

def texToItem(d):
    b = """
<root>
    <using namespace="ALApps.Graphics.Interface" as="agi" />
    <item>
        <agi.TextureBlock Width="40" Height="40" Color="Color.White" />
    </item>
</root>"""
    output = parseItem(b)
    output.OnFocused += onFocused
    output.OnLostFocus += onLostFocus
    output.OnMouseLeftClicked += onMouseLeftClicked
    output.OnMouseLeftReleased += onMouseLeftReleased
    output.Texture = d
    output.Name = d.GetHashCode().ToString()
    return output

def onFocused(s, e):
    s.Color = mxf.Color.LightGreen

def onLostFocus(s, e):
    s.Color = mxf.Color.White

def onMouseLeftClicked(s, e):
    s.Color = mxf.Color.Green
    setBrushTexture(s.Texture)

def onMouseLeftReleased(s, e):
    s.Color = mxf.Color.LightGreen

def setWorkBenchTool(str):
    Engine['workbench'].SetTool(str)

def drawSel_OnMouseLeftReleased(s, e):
    setWorkBenchTool("Draw")